﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Data;
using System.Text;
using Framework;

namespace UserControls.Popups
{
    public partial class UpdatePopup : System.Web.UI.UserControl
    {
        
        #region Fields
        private string title;
        private string desc;
        private string pictureId;
        private string link;
        #endregion

        #region Properties

        public string Description
        {
            get { return desc; }
            set { desc = value; }
        }

        public string Title
        {
            get { return title; }
            set { title = value; }
        }

        public string PictureId
        {
            get { return pictureId; }
            set { pictureId = value; }
        }

        public string Link
        {
            get { return link; }
            set { link = value; }
        }
        #endregion

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
        }
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
        }
        protected override void CreateChildControls()
        {
            base.CreateChildControls();
            //if (Session[SessionConstants.SessionImageId] != null)
            //{
            //    PictureId = MappingTool.CatchNull(Session[SessionConstants.SessionImageId]);
            //    List<VOImage> allImages = Session[SessionConstants.SessionListImages] as List<VOImage>;
            //    VOImage img = (from imgSelected in allImages.ToList()
            //                   where string.Compare(imgSelected.Id,PictureId) == 0
            //                   select imgSelected).FirstOrDefault();
            //    if (img != null)
            //    {
            //        txtTitle.Text = img.Title;
            //        txtDesc.Text = img.Description;
            //        hiddenPictureId.Value = img.Id;
            //    }
            //    Session.Contents.Remove(SessionConstants.SessionImageId);
            //}
        }

        private void setNewValues()
        {
            VOImage img = ImageData.GetImage2(hiddenPictureId.Value.ToString());
            txtTitle.Text = img.Title;
            txtDesc.Text = img.Description;
        }

        protected void save_Click(object sender, EventArgs e)
        {
            VOImage imgToUpdate = new VOImage();
            imgToUpdate.Id = hiddenPictureId.Value;
            imgToUpdate.Title = txtTitle.Text;
            imgToUpdate.Description = txtDesc.Text;
            ImageData.UpdateImage(imgToUpdate);
         //   Response.Redirect(HttpContext.Current.Request.Url.AbsoluteUri, true);
            setNewValues();
        }
    }
}